package br.com.massai.model.dao;

import javax.ejb.Stateless;
import javax.persistence.NoResultException;

import br.com.massai.model.entity.AccessControl;
import br.com.massai.model.entity.Collaborator;
import br.com.massai.model.exceptions.SystemException;

@Stateless
public class AccessControlDAO extends GenericDAO<AccessControl> implements AccessControlRepository {

	private static final long serialVersionUID = 3907326280441849695L;
	
	public AccessControlDAO(){
		super(AccessControl.class);
	}

	@Override
	public AccessControl getLastAccessByUser(Collaborator collaborator) throws SystemException {
		try {
			return (AccessControl) em.createNamedQuery("AccessControl.lastAccess").setParameter("user", collaborator).getSingleResult();

		} catch (NoResultException e) {
			e.printStackTrace();
			return null;
		}
	}
}